package com.example.onlineshop.controller;

import com.example.onlineshop.common.AppResult;
import com.example.onlineshop.model.product.Product;
import com.example.onlineshop.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/api")
@RestController
@CrossOrigin
@Slf4j
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/products", produces = "application/json")
    public AppResult<List<Product>> product() {
        log.info("请求产品列表");
        AppResult<List<Product>> product = productService.product();
        log.info("响应产品列表:{}", product);
        return product;
    }
}
